package cn.sourcespro.spring.service.impl;

import cn.sourcespro.spring.crudparams.PageInfo;
import cn.sourcespro.spring.dao.MenuMapper;
import cn.sourcespro.spring.entity.Menu;
import cn.sourcespro.spring.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 菜单
 *
 * @author 张浩伟
 * @date 2018/07/27
 */
@Service
public class MenuServiceImpl implements MenuService {

    private static final Logger logger = LoggerFactory.getLogger(MenuServiceImpl.class);

    @Autowired
    private MenuMapper mapper;

    @Override
    public Menu add(Menu record) {

        int result = mapper.insert(record);
        if (result > 0) {
            return record;
        }
        return null;
    }

    @Override
    public Menu update(Menu record) {
        Integer id = record.getId();
        if (id == null) {
            return null;
        }
        Menu dbMenu = mapper.selectByPrimaryKey(id);
        if (dbMenu == null) {
            return null;
        }
        int result = mapper.updateByPrimaryKey(dbMenu);
        if (result > 0){
            return dbMenu;
        }
        return null;
    }

    @Override
    public Menu findById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Menu findByUuid(String uuid) {
        return mapper.findByUuid(uuid);
    }

    @Override
    public List<Menu> findAll(PageInfo pageInfo) {
        return mapper.selectAll(pageInfo);
    }

    @Override
    public int selectCount(PageInfo pageInfo) {
        return mapper.selectCount(pageInfo);
    }

    @Override
    public int batchInsert(List<Menu> list) {
        for (Menu bean : list) {
        }
        return mapper.batchInsert(list);
    }

    @Override
    public List<Menu> batchQueryByIds(List<Integer> ids) {
        return mapper.batchQueryByIds(ids);
    }

    @Override
    public List<Menu> batchQueryByUuids(List<String> uuids) {
        return mapper.batchQueryByUuids(uuids);
    }

    @Override
    public int delete(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int delete(String uuid) {
        return mapper.deleteByUuid(uuid);
    }

    @Override
    public int delete(Menu record) {
        return delete(record.getId());
    }

}